/**
 * OpportunityStatus枚举
 *
 * @author sxf
 * @email sxf02615@163.com
 * @date 2025/1/15
 */
package com.sxf.crm.enums;


/**
 * 商机状态枚举
 * 
 * <p>定义商机在不同阶段的状态</p>
 * 
 * @author sxf
 * @email sxf02615@163.com
 * @date 2025/6/1
 */
public enum OpportunityStatus {
    /**
     * 未分配
     */
    UNASSIGNED("UNASSIGNED", "未分配"),

    /**
     * 已分配未认领
     */
    ASSIGNED_UNCLAIMED("ASSIGNED_UNCLAIMED", "已分配未认领"),

    /**
     * 已认领
     */
    CLAIMED("CLAIMED", "已认领"),

    /**
     * 已跟进
     */
    FOLLOWED_UP("FOLLOWED_UP", "已跟进"),

    /**
     * 进行中
     */
    IN_PROGRESS("IN_PROGRESS", "进行中"),

    /**
     * 暂停中
     */
    PAUSED("PAUSED", "暂停中"),

    /**
     * 待决策
     */
    PENDING_DECISION("PENDING_DECISION", "待决策"),

    /**
     * 谈判中
     */
    NEGOTIATING("NEGOTIATING", "谈判中"),

    /**
     * 已成交
     */
    WON("WON", "已成交"),

    /**
     * 丢失
     */
    LOST("LOST", "丢失"),

    /**
     * 已回收
     */
    RECYCLED("RECYCLED", "已回收"), 
    
    /**
     * 已接受
     */
    ACCEPTED("ACCEPTED", "已接受"), 
    
    /**
     * 已拒绝
     */
    REJECTED("REJECTED", "已拒绝");

    private final String code;
    private final String description;

    OpportunityStatus(String code, String description) {
        this.code = code;
        this.description = description;
    }

    public String getCode() {
        return code;
    }

    public String getDescription() {
        return description;
    }

    /**
     * 根据code获取枚举值
     *
     * @param code 枚举code
     * @return 对应的枚举值，如果不存在返回null
     */
    public static OpportunityStatus getByCode(String code) {
        for (OpportunityStatus status : values()) {
            if (status.getCode().equals(code)) {
                return status;
            }
        }
        return null;
    }

    /**
     * 判断状态是否可以认领
     *
     * @return 是否可以认领
     */
    public boolean canBeClaimed() {
        return this == UNASSIGNED || this == ASSIGNED_UNCLAIMED;
    }

    /**
     * 判断状态是否可以分配
     *
     * @return 是否可以分配
     */
    public boolean canBeAssigned() {
        return this == UNASSIGNED;
    }

    /**
     * 判断状态是否可以回收
     *
     * @return 是否可以回收
     */
    public boolean canBeRecycled() {
        return this == CLAIMED || this == FOLLOWED_UP || this == IN_PROGRESS || 
               this == PAUSED || this == PENDING_DECISION || this == NEGOTIATING;
    }

    /**
     * 判断状态是否已结束
     *
     * @return 是否已结束
     */
    public boolean isEnded() {
        return this == WON || this == LOST || this == RECYCLED;
    }
}